package cn.tedu.eb_film.controller;

import cn.tedu.eb_film.pojo.dto.CsRevocationRegulationAddNewDTO;
import cn.tedu.eb_film.pojo.dto.CsRevocationRegulationUpdateDTO;
import cn.tedu.eb_film.pojo.dto.OrderAddNewDTO;
import cn.tedu.eb_film.pojo.dto.OrderUpdateDTO;
import cn.tedu.eb_film.pojo.vo.CsRevocationRegulationListItemVO;
import cn.tedu.eb_film.pojo.vo.CsRevocationRegulationStandardVO;
import cn.tedu.eb_film.pojo.vo.OrderListItemVO;
import cn.tedu.eb_film.pojo.vo.OrderStandardVO;
import cn.tedu.eb_film.service.CsRevocationRegulationService;
import cn.tedu.eb_film.service.OrderService;
import cn.tedu.eb_film.utils.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 处理退票规制相关请求的控制器类
 *
 * @author zzzzc
 * @version 0.0.1
 */

@Api(tags = "退票规制管理模块")
@Slf4j
@RestController
@RequestMapping("/csRevocationRegulations")
@Validated
public class CsRevocationRegulationController {

    @Autowired
    private CsRevocationRegulationService csRevocationRegulationService;
    public CsRevocationRegulationController(){
        log.debug("创建控制器类对象：CsRevocationRegulationController");
    }

    // http://localhost:8888/employees/add-new
    @PostMapping("/add-new")
    @ApiOperation("添加退票规制")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@Valid @RequestBody CsRevocationRegulationAddNewDTO addNewDTO){
        log.debug("开始处理【添加退票规制】的请求，参数：{}",addNewDTO);
        csRevocationRegulationService.addNew(addNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("删除退票规制")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "退票规制ID", required = true, dataType = "long")
    public JsonResult<Void> delete(@PathVariable@Range(min = 1,message = "请提交有效的id")Integer id){
        csRevocationRegulationService.delete(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改退票规制")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "退票规制ID", required = true, dataType = "long")
    public JsonResult<Void> updateInfoById(@PathVariable@Range(min = 1,message = "请提交有效的id")Integer id,
                                           @Valid @RequestBody CsRevocationRegulationUpdateDTO csRevocationRegulationUpdateDTO){
        log.debug("开始处理【修改退票规制详情】的请求，ID：{}，新数据：{}", id, csRevocationRegulationUpdateDTO);
        csRevocationRegulationService.updateInfoById(id,csRevocationRegulationUpdateDTO);
        return JsonResult.ok();
    }

    @GetMapping("/{id:[0-9]+}/select")
    @ApiOperation("根据id查询退票规制")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "退票规制ID", required = true, dataType = "long")
    public JsonResult<CsRevocationRegulationStandardVO> getStandardById(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Integer id){
        log.debug("开始处理【根据ID查询退票规制详情】的请求，参数：{}", id);
        CsRevocationRegulationStandardVO standardById = csRevocationRegulationService.getStandardById(id);
        return JsonResult.ok(standardById);
    }

    @GetMapping("")
    @ApiOperation("查询退票规制列表")
    @ApiOperationSupport(order = 410)
    public JsonResult<List<CsRevocationRegulationListItemVO>> list(){
        log.debug("开始处理【查询退票规制列表】的请求，无参数");
        List<CsRevocationRegulationListItemVO> list = csRevocationRegulationService.list();
        return JsonResult.ok(list);
    }
    @ApiOperation("启用")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "品牌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/enable")
    public JsonResult<Void> setEnable(@PathVariable Integer id) {
        log.debug("开始处理【启用品牌】的请求，参数：{}", id);
        csRevocationRegulationService.setEnable(id);
        return JsonResult.ok();
    }

    // http://localhost:9080/brands/9527/disable
    @ApiOperation("禁用")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name = "id", value = "品牌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/disable")
    public JsonResult<Void> setDisable(@PathVariable Integer id) {
        log.debug("开始处理【禁用品牌】的请求，参数：{}", id);
        csRevocationRegulationService.setDisable(id);
        return JsonResult.ok();
    }

    @PostMapping("/search")
    public JsonResult<List<CsRevocationRegulationListItemVO>> search(@RequestBody CsRevocationRegulationAddNewDTO csRevocationRegulationAddNewDTO){
        List<CsRevocationRegulationListItemVO> list = csRevocationRegulationService.search(csRevocationRegulationAddNewDTO.getConnect());
        return JsonResult.ok(list);

    }
}
